package com.bicon.botu.medical.api

import com.baomidou.mybatisplus.plugins.Page
import com.bicon.botu.core.base.common.controller.BaseController
import com.bicon.botu.core.base.common.entity.BaseResult
import com.bicon.botu.core.base.common.utils.StringUtils
import com.bicon.botu.medical.common.constant.FoodConstants
import com.bicon.botu.medical.common.enums.FoodCategory
import com.bicon.botu.medical.model.dto.FoodAppDTO
import com.bicon.botu.medical.service.ICustomFoodService
import com.bicon.botu.medical.service.IFoodService
import com.bicon.botu.medical.service.IIndexRecipesService
import io.swagger.annotations.ApiImplicitParam
import io.swagger.annotations.ApiImplicitParams
import io.swagger.annotations.ApiOperation
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.data.jpa.domain.AbstractPersistable_.id
import org.springframework.web.bind.annotation.*

/**
 * @version 1.0.0
 * @author: Gyb
 * @date 2018/7/17
 * @description 食物控制器类
 **/

@RestController
@RequestMapping("/api/food")
open class FoodApi : BaseController() {


    @Autowired
    open lateinit var foodService: IFoodService

    @Autowired
    open lateinit var indexRecipesService: IIndexRecipesService

    /**
     * 分类分页查询食物
     *
     * @param currentPage 当前页
     * @param pageSize    每页显示条数
     * @param type    食物类型
     * @return
     */
    @ApiOperation(value = "分类分页查询食物", notes = "分类分页查询食物")
    @ApiImplicitParams(
            ApiImplicitParam(name = "pageSize", value = "页大小", required = true, dataType = "Int", paramType = "query"),
            ApiImplicitParam(name = "currentPage", value = "当前页", required = true, dataType = "Int", paramType = "query"),
            ApiImplicitParam(name = "type", value = "页大小", required = true, dataType = "FoodCategory", paramType = "query"),
            ApiImplicitParam(name = "foodIdJson", value = "Id json格式列表", required = false, dataType = "String", paramType = "query")
    )
    @GetMapping("/list")
    fun listOfFood(
            @RequestParam pageSize: Int,
            @RequestParam currentPage: Int,
            @RequestParam type: FoodCategory,
            foodIdJson: String
    ): BaseResult<*> {
        var page = Page<FoodAppDTO>(currentPage, pageSize)
        if (type == FoodCategory.CUSTOM) {

        }
        if (type == FoodCategory.SYSTEM) {

        }
        return sendResult200()
    }

    /**
     * 根据搜索词搜索全部食物
     *
     * @param searchWord 关键字
     * @return
     */
    @ApiOperation(value = "关键字词搜索全部食物", notes = "关键字搜索全部食物")
    @ApiImplicitParams(
            ApiImplicitParam(name = "pageNo", value = "当前页码", required = true, dataType = "Int", paramType = "query"),
            ApiImplicitParam(name = "pageSize", value = "每页显示条数", required = true, dataType = "Int", paramType = "query"),
            ApiImplicitParam(name = "searchWord", value = "关键字", required = true, dataType = "String", paramType = "query")
    )
    @PostMapping("/search")
    fun searchFood(
            @RequestParam searchWord: String,
            @RequestParam pageNo: Int,
            @RequestParam pageSize: Int): BaseResult<*> {
        return sendResult200(foodService.searchFood(searchWord, pageNo, pageSize, userId))
    }


    /**
     * 获取食物详情
     *
     * @param foodId   食物id
     * @return
     */
    @ApiOperation(value = "获取食物详情", notes = "获取食物详情")
    @ApiImplicitParams(
            ApiImplicitParam(name = "foodId", value = "食物id", required = true, dataType = "Int", paramType = "query")
    )
    @PostMapping("/detail")
    fun getFoodDetail(
            @RequestParam foodId: Int): BaseResult<*> {
        if (StringUtils.isEmpty(String)) {
            return sendResult400()
        }
        return sendResult200(indexRecipesService.getFoodDetails(foodId))
    }
}